package com.yiduan.apollocrm.views.mediators
{
	
	import com.yiduan.apollocrm.models.Opportunity;
	import com.yiduan.apollocrm.views.NewOrEditOpportunityView;
	
	import org.robotlegs.mvcs.Mediator;
	
	public class NewOrEditOpportunityMediator extends Mediator
	{
		[Inject]
		public var newOrEditOpportunityView:NewOrEditOpportunityView;
		
		public function NewOrEditOpportunityMediator() {
			super();
		}
		
		override public function onRegister():void {
			updateViewData();
		}
		
		private function updateViewData():void {
			if (newOrEditOpportunityView.data == null) {
				newOrEditOpportunityView.currentState = "new";
			} else {
				newOrEditOpportunityView.currentState = "edit";
				var opportunity:Opportunity = newOrEditOpportunityView.data as Opportunity;
				newOrEditOpportunityView.nameInput.text = opportunity.name;
			}
		}
	}
}